package com.codeavatar.catools.helper;

import android.app.Activity;
import android.view.View;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.Toolbar;

import com.codeavatar.catools.R;

/**
 * +----------------------------------------------------------------------
 * | @Author: codeavatar   @Year：2022
 * +----------------------------------------------------------------------
 * | @Email: codeavatar@aliyun.com
 * +----------------------------------------------------------------------
 **/

//返回事件 重写onOptionsItemSelected，组件ID：android.R.id.home
public class CaActionBarHelper {

    private final String TAG = this.getClass().getSimpleName();

    //++++++++++++++++++++++++++++++++++++++
    //++ 外部方法
    //++++++++++++++++++++++++++++++++++++++

    public void toolbar(ActionBar actionBar, String title, int iconResId){
        actionBar.setTitle(title);
        actionBar.setHomeAsUpIndicator(iconResId==0? R.mipmap.ca_bar_goback2:iconResId);
        //去掉logo图标
        actionBar.setDisplayShowHomeEnabled(false);
        //显示返回按扭
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    public void toolbar(ActionBar actionBar, String title, boolean isBack){
        actionBar.setTitle(title);
        //去掉logo图标
        actionBar.setDisplayShowHomeEnabled(false);
        //显示返回按扭
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(isBack);
    }

    public void toolbar(ActionBar actionBar, String title){
        actionBar.setTitle(title);
        //去掉logo图标
        actionBar.setDisplayShowHomeEnabled(false);
        //显示返回按扭
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    private static CaActionBarHelper init;
    public static CaActionBarHelper init(){
        if(null == init){
            init = new CaActionBarHelper();
        }
        return init;
    }

    //++++++++++++++++++++++++++++++++++++++
    //++ 内部方法
    //++++++++++++++++++++++++++++++++++++++

    private CaActionBarHelper(){
        // Private constructor to prevent unwanted construction.
    }
}
